

DEFINE VARIABLE part LIKE pt_part .

DEFINE VARIABLE um LIKE pt_um .

DEFINE VARIABLE ptdesc AS CHARACTER.

DEFINE STREAM bf.

DEFINE VARIABLE str AS CHARACTER.

INPUT FROM VALUE("f:\hk_src\audit\partdata.csv") .

OUTPUT STREAM bf TO VALUE("f:\hk_src\audit\pt_si_plan.txt").

REPEAT ON ERROR UNDO, RETRY :

    IMPORT DELIMITER "," part um ptdesc NO-ERROR .

    PUT STREAM bf "@@batchload hkpppsmt02.p" SKIP .

    FIND FIRST pt_mstr NO-LOCK WHERE pt_part = SUBSTRING(part, 1, LENGTH(part) - 1) 
        OR pt_part = SUBSTRING(part, 1, LENGTH(part) - 1) + "R" NO-ERROR.

    EXPORT STREAM bf part pt_site .

    FIND FIRST ptp_det NO-LOCK WHERE ptp_part = pt_part AND ptp_site = pt_site NO-ERROR.

    str = "- - - - - - - - - - - """ + pt_buyer + """ """ + pt_vend + """ """ + pt_po_site + """ ""P""" +
        " - - - - - - - - - - - - - - - - - - - - - - - """ + ptp__chr01 + """ " + STRING(ptp__dec02) .

    PUT STREAM bf UNFORMATTED str  SKIP .


    PUT STREAM bf "@@end" SKIP.

END.
